<template>
  <h2>当前求和为{{ sum }}</h2>
  <button @click="changeSum">点我sum+1</button>
</template>

<script setup lang="ts">
import { ref, watch } from "vue";
let sum = ref(0);
function changeSum() {
  sum.value += 1;
}
//监视
//watch(谁？,回调函数)
//ref这里不用写value
const stopWatch = watch(sum, (newValue, oldValue) => {
  console.log("sum变化了", newValue, oldValue);
  if (newValue > 10) stopWatch();
});
</script>
